﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using OpenTK;
using OpenTK.Graphics.OpenGL;
namespace Imagiality.MeshProcessing
{
    public class Transform
    {
        private Vector3 position;
        private Vector3 rotation;
        private Vector3 scale;

        public Transform()
        {
            position = new Vector3(0, 0, 0);
            rotation = new Vector3(0, 0, 0);
            scale = new Vector3(1, 1, 1);
        }

        public Transform(Vector3 position, Vector3 rotation, Vector3 scale)
        {
            this.position = position;
            this.rotation = rotation;
            this.scale = scale;
        }

        public void Apply()
        {
            GL.PushMatrix();
            GL.Translate(position);
            GL.Rotate(rotation.X, Vector3d.UnitX);
            GL.Rotate(rotation.Y, Vector3d.UnitY);
            GL.Rotate(rotation.Z, Vector3d.UnitZ);
            GL.Scale(scale);
        }

        // caution
        public void Revert()
        {
            GL.PopMatrix();
        }

        public void Translate()
        {
            GL.PushMatrix();
            GL.Translate(position);
        }

        public void Rotate()
        {
            GL.PushMatrix();
            GL.Rotate(rotation.X, Vector3d.UnitX);
            GL.Rotate(rotation.Y, Vector3d.UnitY);
            GL.Rotate(rotation.Z, Vector3d.UnitZ);
        }

        public void Scale()
        {
            GL.PushMatrix();
            GL.Scale(scale);
        }

        public Vector3 PositionVector
        {
            get 
            {
                return position;
            }
        }

        public Vector3 RotationVector
        {
            get 
            {
                return rotation;
            }
        }

        public Vector3 ScaleVector
        {
            get 
            {
                return scale;
            }
        }

    }
}
